1. /* snmnorm.cpp by K.Tsuru */
  2. // function ID = 105 DRADIX, BRADIX
  3. #ifndef SN_H
  4. #include "sn.h"
  5. #endif
  6. /*********************************************************
  7. SNumber class
  8. It provides the normalization.
  9. The position of figures must be determined before calling.
  10. **********************************************************/
  11. static const char* func = "Normalize";
  12. void SNumber::Normalize()
  13. {
  14. fType w, radix = Radix();
  15. register uint i;
  16. fType* v = figure.Elements();
  17. #ifndef NDEBUG
  18. figure(aHead);
  19. #endif
  20. if(type & DEC_INT){
  21. for(i = aTail; i < aHead; i++){
  22. if( v[i] < radix) continue;
  23. w = v[i];
  24. v[i] = w % radix;
  25. v[i+1] += w / radix;
  26. }
  27. if(v[aHead] >= radix){
  28. w = v[aHead];
  29. Reserve(aHead+1); //checking of OVERFLOW_ERR is done in valloc()
  30. v = figure.Elements();
  31. figure[aHead] = w % radix;
  32. figure[aHead+1] = w / radix;
  33. aHead++;
  34. }
  35. while(!v[aTail]) aTail++;
  36. } else {
  37. for(i = aHead; i > aTail; i--){
  38. if( v[i] < radix) continue;
  39. w = v[i];
  40. v[i] = w % radix;
  41. v[i-1] += w / radix;
  42. }
  43. if(v[aTail] >= radix){
  44. //It cannot change the value of SDouble::rdxExp.
  45. if(aTail == 0) SetError(OVERFLOW_ERR, func, 105);
  46. w = v[aTail];
  47. figure[aTail] = w % radix;
  48. figure[aTail-1] = w / radix;
  49. aTail--;
  50. }
  51. while(!v[aHead]) aHead--;
  52. }
  53. //You must call SDouble::Reform() for the real type.
  54. }

snmnorm.cpp : last modifiled at 2017/03/17 11:10:49(1,404 bytes)
created at 2016/04/11 11:36:47
The creation time of this html file is 2017/10/27 10:59:17 (Fri Oct 27 10:59:17 2017).